package com.boarsoft.message.test.other;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import com.boarsoft.message.bean.Message;
import com.boarsoft.rpc.bean.RpcCall;
import com.boarsoft.serialize.ObjectSerializer;

public class SmsMessageSerializer implements ObjectSerializer {

	@Override
	public byte[] serialize(Object obj) throws IOException {
		RpcCall co = (RpcCall) obj;
		Message m = (Message) co.getArguments()[0];
		String s = (String) m.getContent();
		return s.getBytes("UTF-8");
	}

	@Override
	public void serialize(Object obj, OutputStream os) throws IOException {
		RpcCall co = (RpcCall) obj;
		Message m = (Message) co.getArguments()[0];
		String s = (String) m.getContent();
		os.write(s.getBytes("UTF-8"));
	}

	@Override
	public <T> T deserialize(byte[] bytes, Class<T> clazz) throws IOException, ClassNotFoundException {
		return null;
	}

	@Override
	public <T> T deserialize(InputStream is, Class<T> clazz) throws IOException, ClassNotFoundException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object deserialize(InputStream is) throws IOException, ClassNotFoundException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> T deserialize(byte[] bytes, T o) throws ClassNotFoundException, IOException {
		String s = new String(bytes, "UTF-8");
		Message m = new Message();
		m.setTarget("sms_debit");
		m.setContent(s);
		// m.setId(RandomUtil.genUUID());
		RpcCall co = (RpcCall) o;
		co.setArguments(new Object[] { m });
		return o;
	}
}
